//
//  InfiniteWidthButton.swift
//  SwiftUIButton
//
//  Created by 李煜 on 2024/7/30.
//

import SwiftUI

struct InfiniteWidthButton: View {
    var body: some View {
        Button(action: {}, label: {
            Label(
                title: {
                    Text("Delete")
                        .font(.title)
                        .fontWeight(.semibold)
                },
                icon: {
                    Image(systemName: "trash")
                        .font(.title)
                }
            )
            //使用全宽:表示按钮将填满容器视图的宽度
            //***先设置尺寸,不然放到最后无效
            .frame(minWidth: 0, maxWidth: .infinity)
            .padding()
            .background(LinearGradient(colors: [.darkGreen, .lightGreen], startPoint: .leading, endPoint: .trailing))
            .cornerRadius(40)
            .foregroundColor(.white)
            //添加水平额外间距
            .padding(.horizontal, 20)
        })
    }
}

#Preview {
    InfiniteWidthButton()
}
